import requests

from api.get_token import get_login_token


class IhrmEmpApi(object):
    @staticmethod
    def add_emp(token,json_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user",
                             headers={"Authorization": token},
                             json=json_data)
        return resp

    @staticmethod
    def put_emp(token,emp_id,json_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" +emp_id,
                               headers={"Authorization": token},
                               json=json_data)
        return resp

    @staticmethod
    def delete_emp(token,emp_id):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/"+emp_id,
                             headers={"Authorization": token},
                             )
        return resp

    @staticmethod
    def get_emp(token, emp_id):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + emp_id,
                               headers={"Authorization": token},
                               )
        return resp


if __name__ == '__main__':
    token = get_login_token()
    emp_id = "1530111369704177664"

    add_data ={"username": "hzb", "mobile": "13282838897", "workNumber": "123412412412"}
    resp =IhrmEmpApi.add_emp(token,add_data)
    print("增加员工",resp.json())
    #
    # update_data = {"username": "张主"}
    # resp = IhrmEmpApi.put_emp(token,emp_id,update_data)
    # print("修改员工",resp.json())
    #
    # # resp = IhrmEmpApi.delete_emp(token,emp_id)
    # # print("删除员工", resp.json())
    # #
    # resp = IhrmEmpApi.get_emp(token, emp_id)
    # print("查询员工", resp.json())


